/**  **/

var memberId = PKTZ_API.getCookie('memberId');
var subMatchId = PKTZ_API.getCookie('subMatchId');
var param = {
    memberId: memberId,
    subMatchId: subMatchId
};
PKTZ_API.examHistory(param, function () {

    $('.content .subject-ul').find('.options').each(function (t) {
        var that = this;
        //该道题目的标准答案
        var rightKey = $(this).attr('rightKey').split('');
        var userKey = $(this).attr('userKey').split('');
        //用户的答案
        Rendering(rightKey, userKey, $(that));
    });

});

function Rendering(rightKey, userKey, ele) {

    //找出每道题用户选择正确的答案
    var intersection = function (rightKey, userKey, ele) {
        var rightArr = _.intersection(rightKey, userKey);
        if (rightArr.length > 0) {
            ele.find('li').each(function () {
                var that = this;
                var key = $(this).find('.text').attr('keyValue');
                for(var j=0;j<rightArr.length;j++){
                    if(key == rightArr[j]){
                        $(that).addClass('right');
                    }
                }
            })
        }
    };
    intersection(rightKey, userKey, ele);

    //找出每道题用户选择错误的答案
    var differenceWrong = function (rightKey, userKey, ele) {
        var wrongArr = _.difference(userKey, rightKey);
        if (wrongArr.length > 0) {
            ele.find('li').each(function () {
                var that = this;
                var key = $(this).find('.text').attr('keyValue');
                for(var j=0;j<wrongArr.length;j++){
                    if(key == wrongArr[j]){
                        $(that).addClass('wrong');
                    }
                }
            })
        }
    };
    differenceWrong(rightKey, userKey, ele);

    //找出每道题用户未选择的正确答案
    var differenceRight = function (rightKey, userKey, ele) {
        var uncheckedArr = _.difference(rightKey, userKey);
        if (uncheckedArr.length > 0) {
            ele.find('li').each(function () {
                var that = this;
                var key = $(this).find('.text').attr('keyValue');
                for(var j=0;j<uncheckedArr.length;j++){
                    if(key == uncheckedArr[j]){
                        $(that).addClass('right-option');
                    }
                }
            })
        }
    };
    differenceRight(rightKey, userKey, ele);
}
$('.goHome').on('click', function () {
    PKTZ_API.getPageRoute('index');
});